
#import "FYLocalizeableMode.h"
#import "NSUserDefaults+JSafeAccess.h"
#import "ARTConfig.h"

@implementation FYLocalizeableMode
+ (NSString *)FYlocalizedStringKey:(NSString *)translation_key comment:(NSString *)comment {
    
    //    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    //    NSArray * allLanguages = [defaults objectForKey:@"AppleLanguages"];
    //    NSString * preferredLang = [allLanguages objectAtIndex:0];
    NSString *language = [self currentLanguage];
//    NSLog(@"here launage=%@",language);
        
    NSString *string = [NSString localizedStringWithFormat:NSLocalizedString(translation_key, nil),comment];

    if ([language isEqualToString:@"0"]) {
        NSString * path = [[NSBundle mainBundle] pathForResource:@"zh-Hans" ofType:@"lproj"];
        NSBundle * languageBundle = [NSBundle bundleWithPath:path];
        
        string = [NSString localizedStringWithFormat:[languageBundle localizedStringForKey:translation_key value:@"" table:nil],comment ? comment:@""];
    }else if ([language isEqualToString:@"1"]){
        NSString * path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
        NSBundle * languageBundle = [NSBundle bundleWithPath:path];
        
        string = [NSString localizedStringWithFormat:[languageBundle localizedStringForKey:translation_key value:@"" table:nil],comment ? comment:@""];
    }else if ([language isEqualToString:@"2"]){
        NSString * path = [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
        NSBundle * languageBundle = [NSBundle bundleWithPath:path];
        
        string = [NSString localizedStringWithFormat:[languageBundle localizedStringForKey:translation_key value:@"" table:nil],comment ? comment:@""];
    }else if ([language isEqualToString:@"3"]){
        NSString * path = [[NSBundle mainBundle] pathForResource:@"de" ofType:@"lproj"];
        NSBundle * languageBundle = [NSBundle bundleWithPath:path];
        
        string = [NSString localizedStringWithFormat:[languageBundle localizedStringForKey:translation_key value:@"" table:nil],comment ? comment:@""];
    }else if ([language isEqualToString:@"4"]){
        NSString * path = [[NSBundle mainBundle] pathForResource:@"es" ofType:@"lproj"];
        NSBundle * languageBundle = [NSBundle bundleWithPath:path];
        
        string = [NSString localizedStringWithFormat:[languageBundle localizedStringForKey:translation_key value:@"" table:nil],comment ? comment:@""];
        if ([translation_key isEqualToString:@"yongshi"]){
            string = @"tiempo de costo";
        }else if ([translation_key isEqualToString:@"liaocheng"]){
            string = @"curso de tratamiento";
        }
    }else {
        NSString * path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
        NSBundle * languageBundle = [NSBundle bundleWithPath:path];
        
        string = [NSString localizedStringWithFormat:[languageBundle localizedStringForKey:translation_key value:@"" table:nil],comment ? comment:@""];
    }
    if ([translation_key containsString:@"pelvic_floor_treatment_type"]){
        string = string.uppercaseString;
    }
    return string;
}

+ (NSString *)currentLanguage{
    NSString *language = [NSUserDefaults jk_stringForKey:SET_LANGUAGE];
    if (!language) {
        NSString *currentLanguage = [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode];
        if ([currentLanguage containsString:@"zh"]) {
            // 中文
            [NSUserDefaults jk_setObject:@"0" forKey:SET_LANGUAGE];
            language = @"0";
        }else if ([currentLanguage containsString:@"fr"]){
            // 法文
            [NSUserDefaults jk_setObject:@"2" forKey:SET_LANGUAGE];
            language = @"2";
        }else if ([currentLanguage containsString:@"de"]){
            // 德文
            [NSUserDefaults jk_setObject:@"3" forKey:SET_LANGUAGE];
            language = @"3";
        }else if ([currentLanguage containsString:@"es"]){
            // 西文
            [NSUserDefaults jk_setObject:@"4" forKey:SET_LANGUAGE];
            language = @"4";
        }else{
            // 默认为英文
            [NSUserDefaults jk_setObject:@"1" forKey:SET_LANGUAGE];
            language = @"1";
        }
    }
    return language;
}

+ (NSString *)stringOfDailyTitle{
    NSString *language = [self currentLanguage];
    if ([language isEqualToString:@"0"]) {
        // ch
        return @"日常报告";
    }else if ([language isEqualToString:@"1"]){
        // en
        return @"Daily report";
    }else if ([language isEqualToString:@"2"]){
        // fr
        return @"Rapport quotidien";
    }else if ([language isEqualToString:@"3"]){
        // de
        return @"Täglicher Bericht";
    }
    else {
        // en
        return @"Daily report";
    }
}
+ (NSString *)stringOfSleepTitle{
    NSString *language = [self currentLanguage];
    if ([language isEqualToString:@"0"]) {
        // ch
        return @"睡眠报告";
    }else if ([language isEqualToString:@"1"]){
        // en
        return @"Sleep report";
    }else if ([language isEqualToString:@"2"]){
        // fr
        return @"Rapport de sommeil";
    }else if ([language isEqualToString:@"3"]){
        // de
        return @"Schlafbericht";
    }
    else {
        // en
        return @"Sleep report";
    }
}

+ (NSString *)day_treament{
    NSString *language = [self currentLanguage];
    if ([language isEqualToString:@"0"]) {
        // ch
        return @"%@天1次,疗程%@次,用时%@天";
    }else if ([language isEqualToString:@"4"]){
        // es
        return @"Una vez %@ día, %@ del tratamiento, con una duración de %@ días.";
    }else {
        // en
        return @"1 time in %@ days, %@ time in the course of treatment, %@ days";
    }
}
+ (NSString *)times_treament{
    NSString *language = [self currentLanguage];
    if ([language isEqualToString:@"0"]) {
        // ch
        return @"%@天1次,疗程%@/%@次,用时%@分钟";
    }else if ([language isEqualToString:@"4"]){
        // es
        return @"1 times per %@ days, treatment %@/%@ times, duration %s minuto";
    }else {
        // en
        return @"1 times per %@ days, treatment %@/%@ times, duration %@ minutes";
    }
}

@end
